﻿using TMPro;
using UnityEditor;
using UnityEngine;

namespace EchoFramework.Editor
{
    /// <summary>
    /// Echo文本组件TMP菜单
    /// </summary>
    public class EchoTMP_TextMenu
    {
        [MenuItem("EchoFramework/UI/EchoText - TextMeshPro", false, 1)]
        [MenuItem("GameObject/UI/EchoText - TextMeshPro", false, 1)]
        public static GameObject CreateEchoTMP_Text()
        {
            GameObject go = new GameObject("EchoText (TMP)");
            RectTransform rectTrans = go.AddComponent<RectTransform>();
            rectTrans.sizeDelta = new Vector2(350f, 75f);
            if (Selection.activeObject != null && Selection.activeObject is GameObject)
            {
                Transform parentTrans = ((GameObject) Selection.activeObject).transform;
                go.transform.SetParent(parentTrans, false);
            }
            EchoTMP_Text echoTxt = go.AddComponent<EchoTMP_Text>();
            echoTxt.fontSize = 35;
            echoTxt.color = Color.white;
            echoTxt.alignment = TextAlignmentOptions.Midline;
            echoTxt.text = "New EchoText";
            object obj =  Resources.Load<TMP_FontAsset>("Fonts/SmileySans-Oblique SDF");
            echoTxt.font = Resources.Load<TMP_FontAsset>("Fonts/SmileySans-Oblique SDF");
            Selection.activeObject = go;

            return go;
        }
    }
}